package com.vertexnet.realestatenet.model.bean;

// Generated May 22, 2012 8:11:57 AM by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * Installment generated by hbm2java
 */
@Entity
@Table(name = "installment", catalog = "real_estate_net")
public class Installment implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Integer installmentId;
	private PaymentPlan paymentPlan;
	private BigDecimal installmentAmount;
	private String installmentName;
	private int monthDiff;
	private int numRepeat;
	private int yearDiff;
	private Set<Payment> payments = new HashSet<Payment>(0);

	public Installment() {
	}

	public Installment(PaymentPlan paymentPlan, BigDecimal installmentAmount, String installmentName, int monthDiff, int numRepeat, int yearDiff) {
		this.paymentPlan = paymentPlan;
		this.installmentAmount = installmentAmount;
		this.installmentName = installmentName;
		this.monthDiff = monthDiff;
		this.numRepeat = numRepeat;
		this.yearDiff = yearDiff;
	}

	public Installment(PaymentPlan paymentPlan, BigDecimal installmentAmount, String installmentName, int monthDiff, int numRepeat, int yearDiff,
			Set<Payment> payments) {
		this.paymentPlan = paymentPlan;
		this.installmentAmount = installmentAmount;
		this.installmentName = installmentName;
		this.monthDiff = monthDiff;
		this.numRepeat = numRepeat;
		this.yearDiff = yearDiff;
		this.payments = payments;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "installment_id", unique = true, nullable = false)
	public Integer getInstallmentId() {
		return this.installmentId;
	}

	public void setInstallmentId(Integer installmentId) {
		this.installmentId = installmentId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "plan_id", nullable = false)
	public PaymentPlan getPaymentPlan() {
		return this.paymentPlan;
	}

	public void setPaymentPlan(PaymentPlan paymentPlan) {
		this.paymentPlan = paymentPlan;
	}

	@Column(name = "installment_amount", nullable = false)
	public BigDecimal getInstallmentAmount() {
		return this.installmentAmount;
	}

	public void setInstallmentAmount(BigDecimal installmentAmount) {
		this.installmentAmount = installmentAmount;
	}

	@Column(name = "installment_name", nullable = false, length = 25)
	public String getInstallmentName() {
		return this.installmentName;
	}

	public void setInstallmentName(String installmentName) {
		this.installmentName = installmentName;
	}

	@Column(name = "month_diff", nullable = false)
	public int getMonthDiff() {
		return this.monthDiff;
	}

	public void setMonthDiff(int monthDiff) {
		this.monthDiff = monthDiff;
	}

	@Column(name = "num_repeat", nullable = false)
	public int getNumRepeat() {
		return this.numRepeat;
	}

	public void setNumRepeat(int numRepeat) {
		this.numRepeat = numRepeat;
	}

	@Column(name = "year_diff", nullable = false)
	public int getYearDiff() {
		return this.yearDiff;
	}

	public void setYearDiff(int yearDiff) {
		this.yearDiff = yearDiff;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "installment")
	@NotFound(action = NotFoundAction.IGNORE)
	public Set<Payment> getPayments() {
		return this.payments;
	}

	public void setPayments(Set<Payment> payments) {
		this.payments = payments;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Installment) {
		Installment installment = (Installment) obj;
			return new EqualsBuilder()
			.append(this.installmentId, installment.installmentId)
			.append(this.paymentPlan, installment.paymentPlan)
			.append(this.installmentAmount, installment.installmentAmount)
			.append(this.installmentName, installment.installmentName)
			.append(this.monthDiff, installment.monthDiff)
			.append(this.numRepeat, installment.numRepeat)
			.append(this.yearDiff, installment.yearDiff)
			.isEquals();
		}
		return false;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
		.append(this.installmentId)
		.append(this.paymentPlan)
		.append(this.installmentAmount)
		.append(this.installmentName)
		.append(this.monthDiff)
		.append(this.numRepeat)
		.append(this.yearDiff)
		.toHashCode();
	}

	@Override
	public String toString() {
		return getInstallmentName();
	}
}
